#include <bits/stdc++.h>
#define N 100050
#define L 1000005
#define LL long long
#define ms(x) memset(x,0,sizeof(x) )
using namespace std;
struct node{
    bool pd;//out of limit = 1
    int l,r;//the out of limit [ , ]
    bool delpd;//the pd for work2
}car[N];
struct rode{
    bool pd;
    int r;
}proad[L];//mark the unerase road and record its right line to fly over it
int T;
int n,m;
int d[N],p[N],pa[L],havep[L];//pa is havep's sum up
LL v[N],a[N],vlim,ltot;
int ans1=0,ans2=0;
bool C=0;
void init()
{
    //remember to clear because of muiltidetect
    cin>>n>>m>>ltot>>vlim;
    ms(d);ms(v);ms(a);ms(p);ms(car);
    ms(pa);ms(havep);ms(proad);

    ans1=0;ans2=0;C=0;
    for(int i=1;i<=n;i++)
        cin>>d[i]>>v[i]>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>p[i];
        havep[p[i]]++;
    }


    return;
}
void work1()
{
    LL vlimpow=vlim*vlim;
    for(int i=1;i<=n;i++)
    {
        LL vpow=v[i]*v[i];
        if(a[i]==0)
        {
            if(v[i]<=vlim) continue;
            car[i].pd=1;
            car[i].l=d[i];
            car[i].r=ltot;
            continue;
        }
        if(a[i]>0)
        {
            if(v[i]>vlim)
            {
                car[i].pd=1;
                car[i].l=d[i];
                car[i].r=ltot;
            }
            else
            {
                LL xmor=(vlimpow-vpow)/(2*a[i]);
                if(xmor+d[i]>=ltot) continue;
                car[i].pd=1;
                car[i].l=d[i]+xmor+1;
                car[i].r=ltot;
            }
            continue;
        }
        if(a[i]<0)
        {
            C=1;
            if(v[i]<=vlim)
                continue;
            else
            {
                LL xmor=(vpow-vlimpow)/(2*(-a[i]));
                LL xmod=(vpow-vlimpow)%(2*(-a[i]));
                car[i].pd=1;
                car[i].l=d[i];
                if(xmod==0) car[i].r=min(ltot,d[i]+xmor-1);
                else car[i].r=min(ltot,d[i]+xmor);
            }
            continue;
        }


    }
    pa[0]=havep[0];
    for(int i=1;i<=ltot;i++)
        pa[i]=pa[i-1]+havep[i];
    for(int i=1;i<=n;i++)
        if(car[i].l==0) {
            if(pa[car[i].r]> 0) ans1++;
        }
        else if(pa[car[i].r]-pa[car[i].l - 1] > 0) ans1++;


    return;

}
void work2()
{
    for(int k=1;k<=m;k++)
    {
        int recp=p[k];
        p[k]=ltot+1;
        ms(havep);ms(pa);
        int newans=0;
        for(int i=1;i<=m;i++)
            havep[p[i]]++;
        pa[0]=havep[0];
        for(int i=1;i<=ltot;i++)
            pa[i]=pa[i-1]+havep[i];
       // cout<<'\n'<<k<<":";
       // for(int i=0;i<=ltot;i++)
        //    cout<<pa[i]<<" ";
        for(int i=1;i<=n;i++)
            if(car[i].l==0) {
                if(pa[car[i].r]> 0) newans++;
            }
            else if(pa[car[i].r]-pa[car[i].l - 1] > 0) newans++;
    //    cout<<k<<" "<<newans<<endl;
        if(ans1==newans) ans2++;
        else p[k]=recp;


    }



    return;

}
/*
void work2()
{
    for(int i=1;i<=n;i++)
    {
        if(car[i].delpd==0) continue;
        int ln=car[i].l,rn=car[i].r;
        cout<<"\n"<<i<<":"<<ln<<" "<<rn<<"|";
        for(int j=ln;j<=rn;j++)
            if(proad[j].pd==0)
            {
                proad[j].r=rn+1;
                proad[j].pd=1;
                cout<<j<<" ";
            }
            else
            {
                int nxt=proad[j].r;
                while(nxt<=rn&&proad[nxt].pd==1) nxt=proad[nxt].r;
                if(nxt>rn) continue;
                j=nxt;
                cout<<j<<" ";
                proad[j].r=rn+1;
                proad[j].pd=1;
            }
    }
    for(int i=1;i<=m;i++)
        if(proad[p[i]].pd == 0) ans2++;

}*/

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--)
    {
        init();
        work1();
        cout<<ans1<<" ";
        if(ans1==0) cout<<m<<"\n";
        else if(C==0) cout<<m-1<<"\n";
        else{
            work2();
            cout<<ans2<<"\n";
        }
    }
    return 0;
}
